// Copyright (C) 2008 Taylor L. Riche <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#include "lc_deep_op_Operator.h"

void 
deep_op::deepInspect(requestTypes::NetRequest * data, unsigned long dataSize)
{
  bool guilty = false;
  std::string fileName = data->getFileName();
  if(fileName.find("BAD") != std::string::npos) guilty = true;
  if(fileName.find("MALICIOUS") != std::string::npos) guilty = true;
  if(fileName.find("REALLYBAD") != std::string::npos) guilty = true;
  if(fileName.find("YEPWRONG") != std::string::npos) guilty = true;
  if(fileName.find("DIEDIEDIE") != std::string::npos) guilty = true;
  if(fileName.find("YOURMOM") != std::string::npos) guilty = true;
  if(fileName.find("KILLKILLKILL") != std::string::npos) guilty = true;
  if(fileName.find("IZINYOURACCOUNT") != std::string::npos) guilty = true;
  if(fileName.find("NOMNOMNOM") != std::string::npos) guilty = true;
  if(fileName.find("DEADBEEF") != std::string::npos) guilty = true;
  if(fileName.find("BOBO") != std::string::npos) guilty = true;
  if(fileName.find("BUYBUY") != std::string::npos) guilty = true;
  if(fileName.find("GIVEMEYOURCREDITCARD") != std::string::npos) guilty = true;
  if(fileName.find("LIAR") != std::string::npos) guilty = true;
  if(fileName.find("EATIT") != std::string::npos) guilty = true;
  if(fileName.find("EVIL") != std::string::npos) guilty = true;
  if(guilty) {
    requestTypes::ControlMessage * cm = new requestTypes::ControlMessage(requestTypes::GUILTY, data->getSourceID());
    control_out(cm, sizeof(requestTypes::ControlMessage));
  }
  else {
    requestTypes::ControlMessage * cm = new requestTypes::ControlMessage(requestTypes::INNOCENT, data->getSourceID());
    control_out(cm, sizeof(requestTypes::ControlMessage));
  }    
  data_out(data, dataSize);
}

requestTypes::NetRequest *
deep_op::gendata_inRequest()
{
  std::string request = "GET /index.html%ADFASDFSDF.HTML*adfadfEVIL HTTP/1.1";
  request += "\r\n\r\n";
  char * request_str = new char[request.length()];
  strcpy(request_str, request.c_str());
  //std::cerr << request_str << ":" << strlen(request_str) << ":" << request.length() << std::endl;
  return new requestTypes::NetRequest(request_str,strlen(request_str),0);

}

